package StudyCode.summary.myfile;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;

/**
 * 版权所有 科技与人文(www.tah1986.com)
 */
public class GetBytesFromFile {
	public static void main(String[] argv) throws Exception {
		File file = new File("E:\\CODE\\JAVA\\ReviewCode\\src\\StudyCode\\summary\\myfile/GetBytesFromFile.java");
		System.out.println(java.util.Arrays.toString(getBytesFromFile(file)));
	}

	private static byte[] getBytesFromFile(File file) throws IOException {
		InputStream is = new FileInputStream(file);

		long length = file.length();

		byte[] bytes = new byte[(int) length];

		int offset = 0;
		int numRead = 0;
		while (offset < bytes.length && (numRead = is.read(bytes, offset, bytes.length - offset)) >= 0) {
			offset += numRead;
		}

		is.close();
		return bytes;
	}
}
